function Supplier_Code() {
	var buffer = new StringBuffer();
	buffer.append('<div id="find" class="finds2"><div class="searchinput ui-border-radius"><input id="keyword" class="bordersolid" type="text" value="" onblur="Show_Search()" onkeyup="Supplier_Search();"/><div id="searchicon" class="searchicon"><img src="img/jing.jpg"/></div><div id="searchicons" class="searchicons"><img src="img/jings.jpg"/></div></div></div>');
	buffer.append('<div class="horizen border-bottom"></div>');
	return buffer.toString();
};

function Supplier_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		buffer.append('<div class="customerlist border-bottom" id="'+info.ID+'"><div class="customername">'+info.Name+'</div><div class="customerinfo"><div class="state">联系人：'+info.ContactName.ToString()+'</div><div class="lastconntime">'+info.CreateDate.ToTime()+'</div></div></div>');
	});
	return buffer.toString();
};

function Receive_Supplier(pageindex)
{
	var data = {};
			data.act = "Find_Supplier";
			data.userid=userid;
			data.comid=comid;
			data.pageindex=pageindex;
			data.source=source;
			data.pagesize=PAGE_SIZE20;
			data.keyword = $("#keyword").val();
		    data.timer = "";
		    data.sign=GetSign(data.act);
			mui.getJSON(crm_domain, data, function(json) {
				if(json.data.list.length>0)
				{
					if(pageindex==1)
					{
						$("#contentlist1").html(Supplier_Data(json.data.list));
					}else{
						$("#contentlist1").append(Supplier_Data(json.data.list));
					}
					setTimeout(function(){
						Init_Supplier();
						myScroll1.refresh();
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
					if(json.data.list.length!=data.pagesize)
					{
						$("#loading1").html("");
					}else{
						$("#loading1").html('<img src="img/loading.gif"/>');
					}
				}else
				{
					
					if(pageindex==1)
					{
						$("#contentlist1").html("");
						$("#loading1").html("主人，没有找到您需要的数据"); 
					}
					else
					{
						$("#loading1").html("没有更多了");
					}
				}
				
         		pageindex = parseInt($("#divmsg1").attr("pageindex"))+1;
         		$("#divmsg1").attr("pageindex",pageindex);
			});
};

function Supplier_Search(){
	Receive_Supplier(1);
};

function Init_Supplier()
{
	mui("#contentlist1").off("tap",".customerlist");
	mui("#contentlist1").off("longtap",".customerlist");
	mui("#contentlist1").on("tap",".customerlist",function(){
		OpenWindow2(2,"供应商详情","操作",function(){
			SupplierTool(); 
		});
		obj=$(this);
		$("#contentlist2").html(SupplierInfo_Code());
		get("contentlist2").addEventListener("tap",function(){
			if($(".customertool").length>0)
			{
				$(".customertool").hide();
			}
		});
		Init_SupplierDetail();
	});
	mui("#contentlist1").on("longtap",".customerlist",function(){
		obj=$(this);
		plus.nativeUI.confirm("确定要删除吗？", function(event){
				if(event.index==1)
				{
					var data = {};
				    data.act = "Delete_Supplier";
				    data.ids = obj.attr("id");
				    data.userid=userid;
					data.comid=comid;
					data.source=source;
					data.sign=GetSign(data.act);
				    mui.getJSON(crm_domain, data, function(json) {
				    	plus.nativeUI.toast(json.msg);
						if(json.state)
						{
							obj.hide(500);
						}
				    });	
				}
			},"提示", ["取消","确认"]); 
	});
};


